package com.gouying.mall.rabbit.mq;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Hashtable;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class BeanTest {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void send() {

        Map<String, Object> headers = new Hashtable<String, Object>();
        headers.put("name", "jack");
        headers.put("age", 30);
        String content = headers.toString();
        MessageProperties props = MessagePropertiesBuilder.newInstance()
                .setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN).setMessageId("123").setHeader("age", "30")
                .build();
        Message message = MessageBuilder.withBody(content.getBytes()).andProperties(props).build();

        System.out.println("sender1 : " + headers.toString());
        this.rabbitTemplate.convertAndSend("headersExchange", "", message);

    }

}
